﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using syc.Helper;
using System.Drawing;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace syc.Sale.Report
{
    public partial class 重要物资检验情况 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Date1.Text = DateTime.Today.ToString("yyyy年MM月dd日");
                this.Date2.Text = DateTime.Today.ToString("yyyy年MM月dd日");
            }
        }
        protected void Button_Query_Click(object sender, EventArgs e)
        {

            string sql = @"select  原料供货单位ID,管材ID, dbo.原料供货单位.名称,
    dbo.原料.品名,
    dbo.原料.规格,管材到货明细.到货日期,
    dbo.管材到货明细.检定日期,
    dbo.管材到货明细.送检日期,
    sum(管材到货明细.磅重) as 数量
    ,dbo.原料合格数(原料供货单位ID,管材ID,检定日期,管材到货明细.磅重) as 合格量,
    [dbo].[原料不合格数](原料供货单位ID,管材ID,检定日期,管材到货明细.磅重) as 不合格量,
    (dbo.原料合格数(原料供货单位ID,管材ID,检定日期,管材到货明细.磅重)/sum(管材到货明细.磅重))*100 as 合格率 from 管材到货明细
inner join 
dbo.原料供货单位 ON dbo.原料供货单位.ID = dbo.管材到货明细.原料供货单位ID 
INNER JOIN
dbo.原料 ON dbo.管材到货明细.管材ID = dbo.原料.ID  
        where 管材到货明细.到货日期 between '*Date1' and '*Date2'     
group by 到货日期,原料供货单位ID,管材ID, dbo.原料供货单位.名称,
    dbo.原料.品名, 
    dbo.原料.规格,管材到货明细.磅重,dbo.管材到货明细.检定日期,管材到货明细.送检日期  order by 品名 desc";
            sql = sql.Replace("*Date1", DateTime.Parse(this.Date1.Text).ToString());
            sql = sql.Replace("*Date2", DateTime.Parse(this.Date2.Text).ToString());
            this.SqlDataSource1.SelectCommand = sql;
            GridViewHelper helper = new GridViewHelper(this.GridView1);
            helper.RegisterGroup("品名", true, true);
            helper.GroupHeader += new GroupEvent(helper_GroupHeader);
            helper.ApplyGroupSort();     
            this.GridView1.DataBind();          
        }
        //自定义分组标题样式
        private void helper_GroupHeader(string groupName, object[] values, GridViewRow row)
        {
            row.Cells[0].HorizontalAlign = HorizontalAlign.Left;
            row.Cells[0].Height = 33;
            row.BackColor = Color.LightGray;
            row.Cells[0].Text = "&nbsp;&nbsp;" + row.Cells[0].Text;

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //Response.Clear();
            //Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
            //Response.Charset = "utf-8";
            // If you want the option to open the Excel file without saving than
            // comment out the line below
            //Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //Response.ContentType = "application/vnd.doc";
//            //设置EXCEL的表头信息
//            var title = "重要物资检验情况表";
//            HttpContext.Current.Response.Write(
//    @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
//<html>
//<head>
//<meta http-equiv=""Content-Language"" content=""zh-cn""/>
//<meta http-equiv=""Content-Type"" content="" "
//    + HttpContext.Current.Response.ContentType + "; charset=utf-8\"/></head><body><h2><center>" + title + "</center></h2>");
//            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
//            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//            GridView1.RenderControl(htmlWrite);
//            Response.Write(stringWrite.ToString());
//            HttpContext.Current.Response.Write("</body></html>");
//            Response.End();
            string part1 =
@"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel'
xmlns='http://www.w3.org/TR/REC-html40'
<meta http-equiv=Content-Type content='text/html; charset=utf-8'>

<style>
<!--table
	{mso-displayed-decimal-separator:'\.';
	mso-displayed-thousand-separator:'\,';}
@page
	{margin:1.0in .75in 1.0in 1.14in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-page-orientation:landscape;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;
}
.xl24
	{mso-style-parent:style0;
	text-align:center;
	border:.5pt solid windowtext;}
.xl25
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl26
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid black;
	border-left:.5pt solid windowtext;}
.xl27
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid black;
	border-left:.5pt solid windowtext;
}
.xl28
	{mso-style-parent:style0;
	font-size:18.0pt;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl280
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl29
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl30
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid black;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>9</x:ActiveRow>
       <x:ActiveCol>3</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>7200</x:WindowHeight>
  <x:WindowWidth>10620</x:WindowWidth>
  <x:WindowTopX>480</x:WindowTopX>
  <x:WindowTopY>15</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=881 style='border-collapse:
 collapse;table-layout:fixed;width:662pt'>
 <col width=108 style='mso-width-source:userset;mso-width-alt:3456;width:81pt'>
 <col width=118 style='mso-width-source:userset;mso-width-alt:3776;width:89pt'>
 <col width=95 style='mso-width-source:userset;mso-width-alt:3040;width:71pt'>
 <col width=101 style='mso-width-source:userset;mso-width-alt:3232;width:76pt'>
 <col width=86 style='mso-width-source:userset;mso-width-alt:2752;width:65pt'>
 <col width=85 style='mso-width-source:userset;mso-width-alt:2720;width:64pt'>
 <col width=72 span=4 style='width:54pt'>
 <tr height=52 style='mso-height-source:userset;height:39.0pt'>
  <td colspan=10 height=52 class=xl28 width=881 style='height:39.0pt;
  width:662pt'>重要物资检验情况</td>
 </tr>
<tr height=25 style='mso-height-source:userset;height:20.0pt'>
  <td colspan=10 class=xl280 style='height:20.0pt;width:442pt'>时间:*Date1-*Date2</td>
 </tr>
 <tr height=25 style='mso-height-source:userset;height:17pt'>
  <td height=25 class=xl24 style='height:17pt;border-top:none' x:str='品名 '>品名<span
  style='mso-spacerun:yes'> </span></td>
  <td class=xl25 style='border-top:none'>供货单位</td>
  <td class=xl25 style='border-top:none'>规格</td>
  <td class=xl25 style='border-top:none'>到货日期</td>
  <td class=xl25 style='border-top:none'>检定日期</td>
  <td class=xl25 style='border-top:none'>送检日期</td>  
  <td class=xl25 style='border-top:none'>数量</td>
  <td class=xl25 style='border-top:none'>合格量</td>
  <td class=xl25 style='border-top:none'>不合格量</td>
  <td class=xl25 style='border-top:none'>合格率</td>
 </tr>";
 string part3 = @" <![if supportMisalignedColumns]>
  <tr height=0 style='display:none'>
  <td width=108 style='width:81pt'></td>
  <td width=118 style='width:89pt'></td>
  <td width=95 style='width:71pt'></td>
  <td width=101 style='width:76pt'></td>
  <td width=86 style='width:65pt'></td>
  <td width=85 style='width:64pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
 </tr>
 <![endif]>
</table>

</body>

</html>";
            Response.Charset = "utf-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + Server.UrlEncode("重要物资检验表") + ".xls\"");
            part1 = part1.Replace("*Date1", DateTime.Parse(this.Date1.Text).ToString("yyyy年MM月dd日"));
            part1 = part1.Replace("*Date2", DateTime.Parse(this.Date2.Text).ToString("yyyy年MM月dd日"));
            Response.Write(part1);
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            string sql = @"select  原料供货单位ID,管材ID, dbo.原料供货单位.名称,
    dbo.原料.品名,
    dbo.原料.规格,管材到货明细.到货日期,
    dbo.管材到货明细.检定日期,
    dbo.管材到货明细.送检日期,
    sum(管材到货明细.磅重) as 数量
    ,dbo.原料合格数(原料供货单位ID,管材ID,检定日期,管材到货明细.磅重) as 合格量,
    [dbo].[原料不合格数](原料供货单位ID,管材ID,检定日期,管材到货明细.磅重) as 不合格量,
    (dbo.原料合格数(原料供货单位ID,管材ID,检定日期,管材到货明细.磅重)/sum(管材到货明细.磅重))*100 as 合格率 from 管材到货明细
inner join 
dbo.原料供货单位 ON dbo.原料供货单位.ID = dbo.管材到货明细.原料供货单位ID 
INNER JOIN
dbo.原料 ON dbo.管材到货明细.管材ID = dbo.原料.ID  
        where 管材到货明细.到货日期 between '*Date1' and '*Date2'     
group by 到货日期,原料供货单位ID,管材ID, dbo.原料供货单位.名称,
    dbo.原料.品名, 
    dbo.原料.规格,管材到货明细.磅重,dbo.管材到货明细.检定日期,管材到货明细.送检日期  order by 品名 desc";
            sql = sql.Replace("*Date1", DateTime.Parse(this.Date1.Text).ToString());
            sql = sql.Replace("*Date2", DateTime.Parse(this.Date2.Text).ToString());
            Cmd.CommandText = sql;
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(sql, Conn);
            sda.Fill(ds);
            DataTable dt = ds.Tables[0];
            int 油管光管 = dt.Select("品名='油管光管'").Count();
            int 套管光管 = dt.Select("品名='套管光管'").Count();
            int 油管接箍光管 = dt.Select("品名='油管接箍光管'").Count();
            int 套管接箍光管 = dt.Select("品名='套管接箍光管'").Count();
            int 成品套管接箍 = dt.Select("品名='成品套管接箍'").Count();
            SqlDataReader Reader = Cmd.ExecuteReader();
            int i = 0;
            int j = 0;
            int k = 0;
            int l = 0;
            int m = 0;
            while (Reader.Read())
            {
                if (Reader.GetString(3) == "油管光管")
                {
                    if (i == 0)
                    {
                        Response.Write(" <tr style='mso-height-source:userset;'><td rowspan=" + 油管光管 + "  class=xl30 style='border-bottom:.5pt solid black;border-top:none'>" + Reader.GetString(3) + "</td>");
                    }
                    i++;
                    Response.Write(" <td class=xl27 style='border-left:none;'>" + Reader.GetString(2) + "</td>");
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(4) + "</td>");
                    if (Reader.IsDBNull(5))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(5).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(6))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(6).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(7))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(7).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(8))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDecimal(8) + "</td>");
                    }
                    if (Reader.IsDBNull(9))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(9) + "</td>");
                    }
                    if (Reader.IsDBNull(10))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(10) + "</td>");
                    }
                    if (Reader.IsDBNull(11))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td></tr>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(11) + "</td></tr>");
                    }

                }

                if (Reader.GetString(3) == "套管光管")
                {
                    if (j == 0)
                    {
                        Response.Write("<tr height=25 style='mso-height-source:userset;height:17pt'><td rowspan=" + 套管光管 + " height=75 class=xl30 style='border-bottom:.5pt solid black;border-top:none'>" + Reader.GetString(3) + "</td>");
                    }
                    j++;
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(2) + "</td>");
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(4) + "</td>");
                    if (Reader.IsDBNull(5))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(5).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(6))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(6).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(7))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(7).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(8))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDecimal(8) + "</td>");
                    }
                    if (Reader.IsDBNull(9))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(9) + "</td>");
                    }
                    if (Reader.IsDBNull(10))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(10) + "</td>");
                    }
                    if (Reader.IsDBNull(11))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td></tr>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(11) + "</td></tr>");
                    }
                }
                if (Reader.GetString(3) == "油管接箍光管")
                {
                    if (k == 0)
                    {
                        Response.Write("<tr height=25 style='mso-height-source:userset;height:17pt'><td rowspan=" + 油管接箍光管 + " height=75 class=xl30 style='border-bottom:.5pt solid black;border-top:none'>" + Reader.GetString(3) + "</td>");
                    }
                    k++;
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(2) + "</td>");
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(4) + "</td>");
                    if (Reader.IsDBNull(5))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(5).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(6))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(6).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(7))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(7).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(8))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDecimal(8) + "</td>");
                    }
                    if (Reader.IsDBNull(9))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(9) + "</td>");
                    }
                    if (Reader.IsDBNull(10))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(10) + "</td>");
                    }
                    if (Reader.IsDBNull(11))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td></tr>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(11) + "</td></tr>");
                    }
                }
                if (Reader.GetString(3) == "套管接箍光管")
                {
                    if (l == 0)
                    {
                        Response.Write("<tr height=25 style='mso-height-source:userset;height:17pt'><td rowspan=" + 套管接箍光管 + " height=75 class=xl30 style='border-bottom:.5pt solid black;border-top:none'>" + Reader.GetString(3) + "</td>");
                    }
                    l++;
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(2) + "</td>");
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(4) + "</td>");
                    if (Reader.IsDBNull(5))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(5).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(6))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(6).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(7))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(7).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(8))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDecimal(8) + "</td>");
                    }
                    if (Reader.IsDBNull(9))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(9) + "</td>");
                    }
                    if (Reader.IsDBNull(10))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(10) + "</td>");
                    }
                    if (Reader.IsDBNull(11))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td></tr>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(11) + "</td></tr>");
                    }
                }
                if (Reader.GetString(3) == "成品套管接箍")
                {
                    if (m == 0)
                    {
                        Response.Write("<tr style='mso-height-source:userset;'><td rowspan=" + 成品套管接箍 + " class=xl30 style='border-bottom:.5pt solid black;border-top:none'>" + Reader.GetString(3) + "</td>");
                    }
                    m++;
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(2) + "</td>");
                    Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetString(4) + "</td>");
                    if (Reader.IsDBNull(5))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(5).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(6))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(6).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(7))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDateTime(7).ToString("yyyy-MM-dd") + "</td>");
                    }
                    if (Reader.IsDBNull(8))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDecimal(8) + "</td>");
                    }
                    if (Reader.IsDBNull(9))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(9) + "</td>");
                    }
                    if (Reader.IsDBNull(10))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(10) + "</td>");
                    }
                    if (Reader.IsDBNull(11))
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'></td></tr>");
                    }
                    else
                    {
                        Response.Write(" <td class=xl27 style='border-left:none'>" + Reader.GetDouble(11) + "</td></tr>");
                    }
                }
                
               
            }
            Response.Write(part3);
            Response.End();
        }

        //为了导出而重载的一个事件，具体看EXPORT TO EXCEL的文章
        public override void VerifyRenderingInServerForm(Control control)
        {

            // Confirms that an HtmlForm control is rendered for the
            //specified ASP.NET server control at run time.
        }
    }
}
